#include "sqlite.hpp"
#include <cassert>

//这个函数有几行数据就会执行几次
int get_sn_name(void *arg,int cowcount,char**row,char**cowname)
{
    for(int i=0;i<cowcount;i++){
        std::cout << cowname[i] << ": " << row[i] << "\n";
    }
    std::cout << "\n";

    //必须返回0，否则程序会abort
    return 0;
}

int main()
{
    SqliteHelper helper("./test.db");

    //创建/打开sqlite数据库文件
    assert(helper.open(SQLITE_OPEN_NOMUTEX));

    //创建数据表
    // std::string create_sql = "create table student(sn int primary key,name varchar(5),score int);";
    // assert(helper.exec(create_sql,nullptr,nullptr));

    //插入数据
    // std::string insert_sql = "insert into student values(1,'张三',90),(2,'李四',91),(3,'王五',99);";
    // assert(helper.exec(insert_sql,nullptr,nullptr));

    //删除数据
    // std::string delete_sql = "delete from student where name like '李四';";
    // assert(helper.exec(delete_sql,nullptr,nullptr));

    //修改数据
    // std::string update_sql = "update student set score = 100 where sn = 1";
    // assert(helper.exec(update_sql,nullptr,nullptr));

    //查询数据
    std::string select_sql = "select * from student";
    assert(helper.exec(select_sql,get_sn_name,nullptr));

    helper.close();
    return 0;
}